**set working directory with data files***
**data from trust games both annonymous and with PID, SES, and race treatments: See Carlin and Love 2016 (BJPS) and Carln, Love, and Young 2020 (JEPS)**
use "OECD data.dta", clear
pwcorr  p1_*_all gsstrust_all, sig obs

sort cname
by cname: pwcorr  p1_anon_all gsstrust_all, sig obs

***reliablity study

 preserve
 **colombia part of reliablity--data from a panel study in Colombia using GSS question**
 use "waves1&2.dta", clear
pwcorr it1*
**corr .42, spain is .46--average if .44
restore
 
  pwcorr  p1_anon_all gsstrust_all, sig
 reg p1_anon_all gsstrust_all, 
 eivreg p1_anon_all gsstrust_all, reliab(gsstrust_all .44)
 di sqrt(.029)
   **mean a correlation of .17**
 gen p1_anon_all_r=p1_anon_all/10

graph bar (mean) p1_anon_all_r (mean) gsstrust_all, over(cname) scheme(s1manual)

pwcorr p1_anon_all gsstrust_all, sig obs
sort ccode2

by ccode2: pwcorr p1_anon_all gsstrust_all, sig obs
preserve
collapse (mean) p1_anon_all gsstrust_all , by(ccode2)

pwcorr p1_anon_all gsstrust_all, sig obs
reg p1_anon_all gsstrust_all

**Trust game and GSS and ESS trust questions data from a panel study in Spain. With treatments and anonymous games. Again, see Carlin and Love in BJPS and Martini and Torcal 2018 (Party Politics) ***
use "spain for OECD.dta", clear
	
loneway trust_people_gss id
icc play1_anon id
loneway play1_anon id
loneway play1_catalan id

xtset id
xtreg play1_anon trust_people_gss


alpha fair_people_ess_w2 help_people_ess_w2 trust_people_ess_w2
pca fair_people_ess_w2 help_people_ess_w2 trust_people_ess_w2
egen ess_trust=rowmean(fair_people_ess_w2 help_people_ess_w2 trust_people_ess_w2)


corr ess_trust play1_anon trust_people_gss


pwcorr play1_basque play1_center_w3 play1_catalan play1_andaluz_w3 play1_left_w3 play1_madrid_w3 play1_pp play1_psoe play1_right_w3 trust_basque_gss4 trust_catalan_gss4 trust_andaluz_w3 trust_leftid_w3 trust_madrid_w3 trust_centerid_w3 trust_rightid_w3 trust_psoeid_w2 trust_ppid_w2, sig
pwcorr   play1_right_w3 play1_pp play1_psoe trust_rightid_w3 trust_ppid_w2 trust_psoeid_w2 , sig



*****macro

use "meta analysis data.dta", clear

pwcorr wdi_gnicappppcon2011 wdi_gnicapcon2005 wdi_gdppppcon2011 wdi_gdpcappppcon2011 wdi_gdpcapcon2005 avsent  wvs_people_trusted wvs_trust_family wvs_trust_neighbourhood wvs_trust_meet_personally wvs_trust_meet_1st_time wvs_trust_another_reli wvs_trust_another_nati, sig obs

reg avsent  wvs_people_trusted, 


reg avsent   receiverendowed  pymentrandom,
predict resid, resid
pwcorr resid wvs_people_trusted, sig obs

reg logit_avsent  wvs_people_trusted, robust
reg logit_avsent  wvs_people_trusted receiverendowed  pymentrandom, robust

**predicting development
gen log_gdp_pcap=ln(wdi_gdpcapcon2005)
reg log_gdp c.avsent  receiverendowed  pymentrandom, robust
reg log_gdp  wvs_people_trusted if e(sample), robust
reg log_gdp c.avsent wvs_people_trusted receiverendowed  pymentrandom if e(sample), robust
reg log_gdp c.avsent wvs_people_trusted receiverendowed  pymentrandom if country~="United States of America" &  e(sample), robust

reg log_gdp c.avsent if  student==0, robust
reg log_gdp  wvs_people_trusted if  student==0, robust
reg log_gdp c.avsent wvs_people_trusted  if e(sample), robust
reg log_gdp c.avsent wvs_people_trusted  if country~="United States of America" &  e(sample), robust


**dataset reliablity test via ratios	
correlate wvs_people_trusted avsent, covariance
generate float avsent_var =  r(Var_2)
generate float wvs_people_var =  r(Var_1)
generate float xy_cov=  r(cov_12) 
di xy_cov/wvs_people_var 
di xy_cov/avsent_var 

***remove usa
reg avsent  wvs_people_trusted if country~="United States of America", robust

**random effects
xtreg avsent  wvs_people_trusted , re


***collapsed by country
sort ccode
collapse avsent  wvs_people_trusted receiverendowed  pymentrandom , by(ccode)
reg avsent  wvs_people_trusted
